﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Manager;
namespace HealthSystem
{
    public partial class ChangePassword : BasePage
    {
        HW_XXX_UserManager manager = new HW_XXX_UserManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetProile();
            }
        }
        private void GetProile()
        {
           this.username.Text = User.Identity.Name;
        }
        protected void save_Click(object sender, EventArgs e)
        {
            string old =SecrityPass.GetPassword(oldpassword.Text.Trim().ToLower());
            string newpass = newpassword.Text.Trim().ToLower();
            string confirm = confirmpassword.Text.Trim().ToLower();
            if (newpass != confirm)
            {
                ExtAspNet.Alert.Show("两次输入的密码不一样");
                return;
            }
            var user = manager.GetById(User.Identity.Name);
            if (old != user.XX_Pass)
            {
                ExtAspNet.Alert.Show("旧密码不正确");
                return;
            }
            try
            {
                if (CustomerProfile.RoleId > 1001 && CustomerProfile.RoleId < 2000)
                {
                    HW_Manger_Admin_UserManager adminUserManager = new HW_Manger_Admin_UserManager();
                    string pass = SecrityPass.GetPassword(newpass);
                    //string pass = System.Configuration.ConfigurationManager.AppSettings["default"].ToString();
                    adminUserManager.ResetPassWord(User.Identity.Name, newpass, pass);
                }
                else
                {
                    manager.ChangePassword(User.Identity.Name, newpass);
                }
                ExtAspNet.Alert.Show("更改密码成功");
            }
            catch
            {
                ExtAspNet.Alert.Show("更改密码出错");
            }

        }
    }
}